package yecq_blockqueue;

import java.util.concurrent.BlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Consumer extends Thread {
    // 具体注释 参考生产者
    private final BlockingQueue<String> buffer;

    public Consumer(String name, BlockingQueue<String> buffer) {
        super(name);
        this.buffer = buffer;
    }

    @Override
    public void run() {
        while (true) {
            try {
                sleep(1000 * Util.getRandomNumber(6));
                
                System.out.println("\t" + this.getName() + " 取出了元素 " + this.buffer.take());
            } catch (InterruptedException ex) {
                Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
